package com.kiln.juxingqs.ui

import android.view.View
import androidx.lifecycle.Observer
import client.global.commlib.dialog.CameraOrSelectDialog
import client.global.commlib.toast.toast
import com.kiln.juxingqs.R
import com.kiln.juxingqs.databinding.ActivityRegisiterBinding
import com.kiln.juxingqs.ui.vm.RegisterViewModel
import java.util.*
import com.kiln.juxingqs.BaseMiddleActivity
import com.kiln.juxingqs.databinding.ActivityRealnameVerifyBinding
import com.kiln.juxingqs.dialog.SelectDateRangeDialog

class RealNameVerifyActivity :
    BaseMiddleActivity<RegisterViewModel, ActivityRealnameVerifyBinding>() {
    override fun getLayout(): Int {
        return R.layout.activity_realname_verify
    }

    override fun initViewModel(): RegisterViewModel = createViewModel()


    override fun initView() {
        binding?.apply {
            login = this@RealNameVerifyActivity
            vm = viewModel

        }
    }

    override fun observerUI() {
        viewModel.realNameVerifyRet.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast(it.message)//实名成功
                    finish()
                } else {
                    toast(it.message)
                }
            }
        })

    }

    fun imgSelect() {
        CameraOrSelectDialog(this).apply {
            suc = {
                viewModel.imgOne.value = it

                this@RealNameVerifyActivity.binding.fontTv.visibility = View.GONE
                this@RealNameVerifyActivity.binding.idFontImg.visibility = View.VISIBLE
                mImgLoader.load(it).into(this@RealNameVerifyActivity.binding.idFontImg)
            }
        }.show()
    }

    fun goTop() {
        SelectDateRangeDialog(this).apply {
            startDate = viewModel.startDate.value
            endDate = viewModel.endDate.value

            isLongDate.set(viewModel.standard.value.equals("长期"))
            selectCli = { s, e ->
                viewModel.startDate.value = s
                viewModel.endDate.value = e
            }
        }.show()
    }
}